

*repair private coding
replace private =0 if dmu ==95139
replace private =0 if dmu ==95168 
replace private =0 if dmu ==95182
replace private =0 if dmu ==95195 
replace private =0 if dmu ==95204 
replace private =0 if dmu ==95206 
replace private =0 if dmu ==95228 
replace private =0 if dmu ==95245 
replace private =0 if dmu ==95255 
replace private =0 if dmu ==95256 
replace private =0 if dmu ==95259 
replace private =0 if dmu ==95260 
replace private =0 if dmu ==95271 
replace private =0 if dmu ==95272 
replace private =0 if dmu ==95274 
replace private =0 if dmu ==95283 
replace private =0 if dmu ==99018 
replace private =0 if dmu ==99020 
replace private =0 if dmu ==2000006 
replace private =0 if dmu ==20120294
replace private =0 if dmu ==95193
drop if private ==1


*Medical School
gen med =0
replace med =1 if medschl =="Yes"
replace med =1 if medschl =="YES"
replace med =1 if medschl =="yes"



*Adjust Price Level
gen cpi =.
replace cpi =1 if year ==1993
replace cpi =1.025606 if year ==1994
replace cpi =1.054671 if year ==1995
replace cpi =1.085813 if year ==1996
replace cpi =1.110727 if year ==1997
replace cpi =1.128028 if year ==1998
replace cpi =1.152941 if year ==1999
replace cpi =1.191696 if year ==2000
replace cpi =1.225606 if year ==2001
replace cpi =1.244983 if year ==2002
replace cpi =1.273356 if year ==2003
replace cpi =1.307266 if year ==2004
replace cpi =1.351557 if year ==2005
replace cpi =1.395156 if year ==2006
replace cpi =1.434893 if year ==2007
replace cpi =1.489986 if year ==2008
replace cpi =1.484686 if year ==2009
replace cpi =1.509038 if year ==2010
replace cpi =1.556671 if year ==2011
replace cpi =1.588886 if year ==2012
replace cpi =1.612159 if year ==2013
replace cpi =1.638311 if year ==2014
replace cpi =1.640256 if year ==2015
replace cpi =1.660948 if year ==2016

gen adjincome = grosslicinc/cpi
gen adjlegfees = legfees/cpi

*Donor Pool
drop if year <1993 |year >2015  
egen wanted = total(inrange(year, 1993, 2015)), by(dmu)  

summarize adjincome totresexp invdisrec adjlegfees actlic if wanted ==23
summarize adjincome totresexp invdisrec adjlegfees actlic if wanted !=23

keep if wanted ==23

*Fixing instutution names
gen firmid = _n
gen school =.
replace school =dmu if school ==.
tostring school, replace
	
*Graphing Outcomes 
egen avgincome = mean(grosslicinc), by(year)
egen tag = tag(year) 
replace avgincome = grosslicinc if dmu==95006
twoway (connected avgincome year if tag | dmu!=95006) (connected avgincome year if dmu==95006)

xtline avgincome, overlay

egen avgfees = mean(legfees), by(year)
egen tagfees = tag(year) 
replace avgfees = legfees if dmu==95006
xtline avgfees, overlay scheme(scientific)

egen avglicenses = mean(actlic), by(year)
egen taglicenses = tag(year) 
replace avglicenses = actlic if dmu==95006
xtline avglicenses, overlay scheme(scientific)

*Testing Models
*Outcomes since 1993, 2001 placebo
synth2 adjincome totresexp(1999) totresexp(2000) totresexp(2001) totresexp(2002)  invdisrec(1999) invdisrec(2000) invdisrec(2001) invdisrec(2002) adjincome(1993) adjincome(1994) adjincome(1995) adjincome(1996) adjincome(1997) adjincome(1998) adjincome(1999) adjincome(2000) adjincome(2001) adjincome(2002), trunit(95006) trperiod(2003) postperiod(2003(1)2015) placebo(period(2001)) loo frame(ASU) nested

synth2 adjlegfees totresexp(1999) totresexp(2000) totresexp(2001) totresexp(2002)  invdisrec(1999) invdisrec(2000) invdisrec(2001) invdisrec(2002) adjlegfees(1993) adjlegfees(1994) adjlegfees(1995) adjlegfees(1996) adjlegfees(1997) adjlegfees(1998) adjlegfees(1999) adjlegfees(2000) adjlegfees(2001) adjlegfees(2002), trunit(95006) trperiod(2003) postperiod(2003(1)2015) placebo(period(2001)) loo frame(ASU) 

synth2 actlic totresexp(1999) totresexp(2000) totresexp(2001) totresexp(2002)  invdisrec(1999) invdisrec(2000) invdisrec(2001) invdisrec(2002) actlic(1993) actlic(1994) actlic(1995) actlic(1996) actlic(1997) actlic(1998) actlic(1999) actlic(2000) actlic(2001) actlic(2002), trunit(95006) trperiod(2003) postperiod(2003(1)2015) placebo(period(2001)) loo frame(ASU) 

synth_runner adjincome adjincome(1993) adjincome(1994) adjincome(1995) adjincome(1996) adjincome(1997) adjincome(1998) adjincome(1999) adjincome(2000) adjincome(2001) adjincome(2002), trunit(95006) trperiod(2003) gen_vars
single_treatment_graphs
effect_graphs
pval_graphs

gen ratio = post_rmspe /pre_rmspe
sort ratio 
drop if dmu ==95191
drop if dmu==95256
*Dropping bad pre treatment fits from placebo
drop if dmu ==95188
drop if dmu ==95219
drop if dmu==95116
drop if dmu==95107
drop if dmu ==95168
histogram ratio

xtline effect if year>=2003, overlay  

*forced Controls
synth2 adjincome totresexp invdisrec med lnfte adjincome(1996) adjincome(1997) adjincome(1998) adjincome(1999) adjincome(2000) adjincome(2001) adjincome(2002), trunit(95006) trperiod(2003) postperiod(2003(1)2015) placebo(period(2001)) loo 

synth2 actlic totresexp invdisrec actlic(1996) actlic(1997) actlic(1998) actlic(1999) actlic(2000) actlic(2001) actlic(2002), trunit(95006) trperiod(2003) postperiod(2003(1)2015) placebo(period(2001)) loo frame(ASU) 


